package com.deliveryservicesystem.app.exceptions;

import com.deliveryservicesystem.app.util.AppUtils;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import javax.swing.JOptionPane;

/**
 * File Name: OutputError.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.app.exceptions
 * Author: Lance
 * Date: Jun 20, 2012
 * Editor:
 */
public class OutputError
{

    /**
     * Output error to user
     *
     * @param ex Exception thrown
     */
    public static void toUser(Exception ex)
    {
        JOptionPane.showMessageDialog(null, ex.toString(), "Error ", JOptionPane.ERROR_MESSAGE);
    }

    /**
     * Output error to log file
     *
     * @param ex Exception thrown
     */
    public static void toLog(Exception ex)
    {
        try
        {
            ex.printStackTrace(new PrintStream(new FileOutputStream("ErrorLog.txt", true)));
        }
        catch (FileNotFoundException exception)
        {
            AppUtils.showUserMessage(null, "Error logging LOG\n" + exception.toString(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}